package com.bq.gametrade.ui.dialog;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.bq.gametrade.R;
import com.bq.gametrade.ui.activity.FriendsTransferActivity;
import com.bq.gametrade.ui.activity.RedEnvelopeListActivity;
import com.bq.gametrade.utils.ToastUtils;

/**
 * 功能：
 * <p>
 *
 * @author Feel on 2016/12/5 16:45
 */

public class RedEnvelopeOrTransferDialog extends DialogFragment {

    private Button btnTransfer, btnRedEnvelope;
    private Button btnCannel;
    private String friendName = "", friendBqAccount = "", friendAccount = "";

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        friendName = getArguments().getString("friendName");
        friendBqAccount = getArguments().getString("friendBqAccount");
        friendAccount = getArguments().getString("friendAccount");
        if (friendBqAccount.equals("") || friendName.equals("") || friendAccount.equals("")) {
            ToastUtils.showToast(getActivity(), "获取好友信息出错，请重试");
            dismiss();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.dimAmount = 0.6f;
        window.setAttributes(lp);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        View view = View.inflate(getActivity(), R.layout.dialog_redenvelopeortransfer, null);
        initView(view);
        getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        Window window = getDialog().getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.dimAmount = 0.0f;
        window.setGravity(Gravity.BOTTOM);
        window.setAttributes(lp);
        getDialog().show();
        return view;
    }

    private void initView(View view) {
        btnTransfer = (Button) view.findViewById(R.id.btn_transfer);
        btnTransfer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), FriendsTransferActivity.class);
                intent.putExtra("friendBqAccount", friendBqAccount);
                intent.putExtra("friendAccount", friendBqAccount);
                intent.putExtra("friendName", friendName);
                startActivity(intent);
                dismiss();
            }
        });
        btnRedEnvelope = (Button) view.findViewById(R.id.btn_redEnvelope);
        btnRedEnvelope.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), RedEnvelopeListActivity.class);
                intent.putExtra("friendBqAccount", friendBqAccount);
                intent.putExtra("friendName", friendName);
                intent.putExtra("friendAccount", friendAccount);
                startActivity(intent);
                dismiss();
            }
        });
        btnCannel = (Button) view.findViewById(R.id.btn_cannel);
        btnCannel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
}
